package A1;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Ferdy
 * Date: 31 Mar 11
 * Time: 14:00:32
 * To change this template use File | Settings | File Templates.
 */
/**all details about grid*/
public class Grid {
        ArrayList<Cars> hCarList = new ArrayList<Cars>();
        ArrayList<Cars> vCarList = new ArrayList<Cars>();
        
    /**set the position of the road to cell*/
    public char[][] road(int horLane, int verLane){
            final int HOR=27;
            final int VER=26;
            char[][] cell= new char[HOR][VER];

            //to set the x,y area
            for (int i=0;i<HOR;i++)
            {
                for (int j=0;j<VER;j++)
                {
                  cell[i][j]=' ';
                }
            }

            for (int i=0;i<10;i++)
            {
                cell[10][i]='-';
                cell[10][10]='|';
                cell[i][10]='|';

                cell[10+horLane+1][i]='-';
                cell[10+horLane+1][10]='|';
                cell[10+1+horLane+1+i][10]='|';
                cell[10+1+horLane+11][10+verLane+1]='|';

                cell[10][10+1+verLane+1+i]='-';
                cell[10][10+1+verLane]='|';
                cell[i][10+verLane+1]='|';

                cell[10+horLane+1][10+1+verLane+1+i]='-';
                cell[10+1+horLane][10+verLane+1]='|';
                cell[10+1+horLane+1+i][10+verLane+1]='|';
                cell[10+1+horLane+11][10]='|';
            }

        return cell;
        }

    /**set the position of the horizontal car to cell*/
    public char[][] gridHorCar(char[][] cell,int count,ArrayList<Cars> hCarList,char TrafficL){
           /* if(hCarList.get(count).getCount()>=26)
            {
                cell[10+hCarList.get(count).getHLane()][26]=' ';
                //hCarList.remove(count);
            }

            else */
            {
            if(hCarList.get(count).getHLane()!=0)
            cell[10+hCarList.get(count).getHLane()][hCarList.get(count).getCount()]='C';

            if(hCarList.get(count).getCount() > 0 && cell[10+hCarList.get(count).getHLane()][hCarList.get(count).getCount()-1]=='C')
            {cell[10+hCarList.get(count).getHLane()][hCarList.get(count).getCount()-1]=' ';}

            hCarList.get(count).setCount(1);}
            return cell;
        }

    /**set the position of the vertical car to cell*/
    public char[][] gridVerCar(char[][] cell,int count,ArrayList<Cars> vCarList,char TrafficL){
            /*if(vCarList.get(count).getCount()>=26)
            {
                cell[10+vCarList.get(count).getHLane()][26]=' ';
                //vCarList.remove(count);
            }

            else*/
            {
            if(vCarList.get(count).getVLane()!=0)
            cell[vCarList.get(count).getCount()][10+vCarList.get(count).getVLane()]='C';

            if(vCarList.get(count).getCount() > 0 && cell[vCarList.get(count).getCount()-1][10+vCarList.get(count).getVLane()]=='C')
            {cell[vCarList.get(count).getCount()-1][10+vCarList.get(count).getVLane()]=' ';}

            vCarList.get(count).setCount(1);}
        return cell;
        }

    /**print the cell*/
    public void printGrid(char[][]cell){
        final int HOR=26;
        final int VER=26;
        for (int i=0;i<HOR;i++)
        {
            for (int j=0;j<VER;j++)
            {
             System.out.print(cell[i][j]);
            }
         System.out.println();
        }
    }



}
